package db

import (
	"context"
	"time"
	"user/internal/config"

	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

func NewMysql(c config.MysqlConfig) sqlx.SqlConn {
	conn := sqlx.NewMysql(c.DataSource)
	db, err := conn.RawDB()
	if err != nil {
		panic(err)
	}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
	defer cancel()

	err = db.PingContext(ctx)
	if err != nil {
		panic(err)
	}

	db.SetMaxOpenConns(100)

	return conn
}
